package com.admin.socketmultiplayer.dialog

import android.content.Context
import android.widget.ImageView
import cn.bmob.v3.BmobQuery
import cn.bmob.v3.BmobUser
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
import com.admin.socketmultiplayer.R
import com.admin.socketmultiplayer.adapter.RoomListAdapter
import com.admin.socketmultiplayer.bean.Room
import com.admin.socketmultiplayer.inteface.DialogListener
import kotlinx.android.synthetic.main.layout_room_list.view.*

/**
 * Created by 吴昶 on 2018/4/25.
 */
class RoomListDialog(context: Context,layout:Int,var listener:DialogListener,theme:Int):BaseDialog(context,layout,theme){

    var user=BmobUser.getCurrentUser()
    var roomAdapter:RoomListAdapter?=null

    override fun initData() {
        var query=BmobQuery<Room>()

        roomAdapter= RoomListAdapter(context, R.layout.layout_room_list_item,null,object:RoomListAdapter.RoomItemClickListener{
            override fun OnItemClickListener(room: Room, image: ImageView, position: Int) {
                listener.selectItemListener(room)
            }

        })
        fview.lv_room_list.adapter=roomAdapter
        query.findObjects(object :FindListener<Room>(){
            override fun done(p0: MutableList<Room>?, p1: BmobException?) {
                p0?.let {
                    roomAdapter!!.upData(p0)
                }
            }
        })
        fview.btn_cancel.setOnClickListener { cancel() }
    }

}